package confidence.tools;

import cn.hutool.extra.pinyin.PinyinUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * 拼音修复
 */
public class PinyinRepair {


    /**
     * 判断两个字符串中有多少个汉字拼音相同
     * @param text1
     * @param text2
     * @return
     */
    public static final int samePinyin(String text1, String text2) {
        int num = 0;
        try {
            if(StringUtils.isBlank(text1) || StringUtils.isBlank(text2)) {
                return num;
            }
            String pinyin1 = PinyinUtil.getPinyin(text1, ",");
            String pinyin2 = PinyinUtil.getPinyin(text2, ",");

            List<String> arr1 = Arrays.asList(pinyin1.split(","));
            List<String> arr2 = Arrays.asList(pinyin2.split(","));


            for(int i=0; i<arr1.size(); i++) {
                if(arr2.contains(arr1.get(i))) {
                    num = num + 1;
                }
            }
        } catch (Exception e) {

        }
        return num;
    }

    public static void main(String[] args) {
        System.out.println(new PinyinRepair().samePinyin("科创石一街战略", "科创十一街略"));
        System.out.println(PinyinUtil.getPinyin("战略",","));
        System.out.println(PinyinUtil.getPinyin("衣裳",","));
    }
}
